#ifndef RING_INCLUDED
#define RING_INCLUDED
// a ring complimented by linked list, and support rotation
// example:
//                          1   2    3   4    5    6
// Ring_T names = Ring_ring("a", "b", "c", "d", "e", NULL);
//                         -5  -4    -3  -2   -1   0
#define T Ring_T
typedef struct T *T;
extern T Ring_new(void);
extern T Ring_ring(void *x, ...);
extern void Ring_free(T *ring);
extern int Ring_length(T ring);
extern void *Ring_get(T ring, int i);
extern void *Ring_put(T ring, int i, void *x);

/**
 * @brief add a element x to the postion of ring
 *
 * @param ring
 * @param pos
 * @param x
 * @return void* return element x
 */
extern void *Ring_add(T ring, int pos, void *x);
// the same as Ring_add(ring, 1, x)
extern void *Ring_addlo(T ring, void *x);
// the same as Ring_add(ring, 0, x)
extern void *Ring_addhi(T ring, void *x);
extern void *Ring_remove(T ring, int i);
extern void *Ring_remlo(T ring);
extern void *Ring_remhi(T ring);

/**
 * @brief reindex the ring; if clock wise rotation, every element's index increse
 *        by n % ring->length
 *
 * @param ring
 * @param n  if n>0, clockwise; else counter clockwise
 */
extern void Ring_rotate(T ring, int n);
#undef T
#endif